<template>
	<view class="login">
		<view class="login-bgc">
			<view class="logo-content">
				<image class="logo" src="../../static/images/zhishuo/logo.png"></image>
				<view>
					<image class="logo-title" src="../../static/images/zhishuo/login-title.png"></image>
				</view>
			</view>
			<view class="form">
				<view class="welcome-title">欢迎来到智说民革高新系统，请登陆～</view>
				<u--form labelPosition="left" :model="model" ref="uForm">
					<u-form-item prop="mobile" style="margin-bottom: 80rpx;">
						<u-input placeholder="请输入手机号" clearable type="text" border="none"
							placeholderClass="loginPlaceText" v-model="model.mobile">
							<template slot="prefix">
								<u-icon name="account" color="#3f91ff" size="20"></u-icon>
							</template>

						</u-input>
					</u-form-item>
					<u-form-item prop="code">
						<u-input placeholder="请输入密码" clearable type="password" border="none"
							placeholderClass="loginPlaceText" v-model="model.code" maxlength="4">
							<template slot="prefix">
								<u-icon name="lock" color="#3f91ff" size="20"></u-icon>
							</template>
						</u-input>
					</u-form-item>



				</u--form>

				<view class="submitBox" @click="toSubmit">
					<!-- :loading="handlerLoading" loadingMode="circle" -->
					<view class="submitBox-btn">登录</view>
					<!-- 	<u-button loadingText="登录中..." @click="toSubmit" text="登 录" class="submit-btn"
						color="linear-gradient(315deg,#3f91ff, #55afff)"></u-button> -->

				</view>
			</view>


		</view>
	</view>
</template>

<script>
	import {
		login
	} from '@/api/index.js';
	import {
		getToken,
		setToken,
		setUserInfo,
		clearAllStorage
	} from '@/utils/storage.js';
	export default {
		options: {
			styleIsolation: 'shared'
		},
		watch: {},
		data() {
			return {
				handlerLoading: false,
				loginTitle: '智说民革高新',
				isRead: [],
				isShake: false,
				model: {
					// mobile: '',
					// code: '',
					mobile: '15850853888',
					code: '6339',
					// mobile: '13270779777',
					// code: '0315',
				},

				rules: {
					mobile: [{
						required: true,
						validator: (rule, value, callback) => {
							return uni.$u.test.mobile(value);
						},
						message: '手机号格式不正确',
						trigger: ['blur'],
					}],
					code: {
						type: 'string',
						required: true,
						message: '请填写密码',
						trigger: ['blur']
					},

				},
			}
		},
		onLaunch() {
			const token = getToken();
			if (token) {
				this.$common.navigateTo('/pages-index/index/index');
			}
		},
		onShow() {

		},
		onReady() {
			// 设置规则
			this.$refs.uForm.setRules(this.rules);
		},
		onShareAppMessage() {},
	
		methods: {
			// toSubmit() { // 提交处理
			// 	// 晃动动画
			// 	if (!this.isRead[0]) {
			// 		this.isShake = true;
			// 		setTimeout(() => {
			// 			this.isShake = false;
			// 		}, 1000)
			// 		return
			// 	}

			// 	// 验证规则
			// 	this.$refs.uForm.validate().then(res => {
			// 		this.toLogin();
			// 	}).catch(errors => {
			// 		// uni.$u.toast('请正确填写表单信息');
			// 	});
			// },
			toSubmit() { // 登录
				// this.handlerLoading = true;

			
				login(this.model).then(res => {
					if (res.errors.length > 0) {
						uni.showToast({
							title: res.errors,
							icon: 'none',
							duration: 2000,
						});
					} else {

						setToken(res.token);
						this.$common.successToShow(res.msg || '登录成功', () => {
							this.$common.navigateTo('/pages-index/index/index');
						});
					}

				}).catch(err => {
					console.log(err);
					this.$common.errorToShow(err)
					// this.handlerLoading = false;
				})

			},

		}
	}
</script>


<style lang="scss" scoped>
	/deep/ .inputClass {
		width: vw(100);
	}


	.login {
		width: 100%;
		height: 100%;
		background-color: #fff;

		.login-bgc {
			background-image: url('');
			width: 100%;
			height: 100%;
			background-size: cover;

			.logo-content {
				text-align: center;
				padding-top: vw(220);

				.logo {
					width: vw(162);
					height: vw(162);
					padding-bottom: vw(10);
				}

				.logo-title {

					width: vw(378);
					height: vw(78);
				}
			}

			/deep/ .u-input__content__subfix-icon {

				.btn {
					width: vw(110);
					color: #3f91ff;
					background-color: transparent;
					font-size: vw(24);
					padding: 0;
					border: 0;
					font-weight: 500;

					&::after {
						border: 0;
					}
				}
			}

			.form {
				background-image: url('');
				width: vw(686);
				height: vw(992);
				border-radius: vw(16);
				margin: vw(40) auto 0px;

				.welcome-title {

					height: vw(36);
					font-size: vw(26);
					font-family: PingFang SC, PingFang SC-Semibold;
					font-weight: bold;
					text-align: left;
					color: #ffffff;

					padding: vw(40) 0px vw(20) vw(32);
					line-height: vw(36);
					margin: vw(40) vw(32) vw(60) vw(10);
				}

				/deep/ .u-form-item {
					margin-bottom: vw(50);
				}

				/deep/ .u-form-item__body__right__message {
					margin-left: vw(20) !important;
					font-size: vw(22);
					line-height: vw(22);
					margin-top: vw(10);
				}

				/deep/ .u-form-item__body {
					padding: 0;
				}

				/deep/ .u-input {
					border: 1px solid #ffffff;
					border-radius: vw(42);
					background-color: #ffffff;
					height: vw(80);
					width: vw(622);
					margin: 0 auto;

					.u-input__content__prefix-icon {
						margin-left: vw(20);
						vertical-align: middle;
						font-size: vw(40);
						height: vw(40);
						line-height: vw(40);
					}

					.u-input__content__field-wrapper__field {
						height: vw(80);
						line-height: vw(80);
						padding: 0 vw(20) 0 vw(30);
						font-size: vw(26) !important;
					}
				}

				/deep/ .loginPlaceText {
					line-height: vw(80);
					color: #999999;
					font-size: vw(26);
				}

				.submitBox {
					// /*兼容 IOS<11.2*/
					// bottom: calc(15vw + constant(safe-area-inset-bottom));
					// /*兼容 IOS>11.2*/
					// bottom: calc(15vw + env(safe-area-inset-bottom));
					width: vw(622);
					height: vw(80);
					background: #3097ff;
					text-align: center;
					display: flex;
					align-items: center;
					justify-content: center;
					box-shadow: 2px 4px 8px 0 rgba(0, 96, 185, 0.3);

					.submitBox-btn {
						color: #fff;
						line-height: vw(80);
						border: 0;
						height: vw(80);

					}




				}

			}

		}
	}
</style>
